package gen.kaynak.navitrack.messageProcessState;

import gen.kaynak.navitrack.messageProcessStrategy.*;

public class SecondDiscovered extends ACMessageProcessState {
	private static SecondDiscovered state = new SecondDiscovered();
	private MessageProcessStrategyManager objCLLP;

	private SecondDiscovered() {

	}

	public static ACMessageProcessState Instance() {
		return state;

	}

	@Override
	void ProcessWhiteSpace(char c, MessageProcessStateManager mpm) {

	}

	@Override
	void ProcessLetter(char c, MessageProcessStateManager mpm) {
		objCLLP = new MessageProcessStrategyManager(new NSEWProcessor());
		if (objCLLP.Process(c, mpm)) {
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
		} else {
			mpm.setSign("+");
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
			if (mpm.alternateProcessing()) {
				ChangeState(mpm, Initial.Instance());
				if (objCLLP.Process(c, mpm)) {
					ChangeState(mpm, NSEWDiscovered.Instance());
				}
			} else {
				mpm.terminateProcessManager();
				// Exit Sub
			}
		}

	}

	@Override
	void ProcessPunctuation(char c, MessageProcessStateManager mpm) {

	}

	@Override
	void ProcessSymbol(char c, MessageProcessStateManager mpm) {
		mpm.setSign("+");
		mpm.calculateCoordinate();
		ChangeState(mpm, CoordinateDiscovered.Instance());

		if (mpm.alternateProcessing()) {
			switch (c) {
			case '+':
				mpm.setSign("+");
				ChangeState(mpm, NSEWDiscovered.Instance());
			case '-':
				mpm.setSign("-");
				ChangeState(mpm, NSEWDiscovered.Instance());
			default:
				ChangeState(mpm, Initial.Instance());
			}
		} else {
			mpm.terminateProcessManager();
		}

	}

	@Override
	void ProcessNumber(char c, MessageProcessStateManager mpm) {
		mpm.setSign("+");
		mpm.calculateCoordinate();
		ChangeState(mpm, CoordinateDiscovered.Instance());

		if (mpm.alternateProcessing()) {
			mpm.appendChar(c);
			ChangeState(mpm, DegreeIntegerProcessing.Instance());
		} else {
			mpm.terminateProcessManager();
		}

	}

}
